package io.renren.modules.study.service;

import io.renren.modules.study.dao.EventMapper;
import io.renren.modules.study.entity.StudyBaseSubject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

@Service
public class EventsService {
    @Autowired
    private EventMapper eventMapper;

    public List<StudyBaseSubject> getSubjectsByEventId(Long eventId) {
        List<StudyBaseSubject> subjects = new ArrayList<>();
        List<String> tableNames = Arrays.asList("subject_a", "subject_event_a");
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("subject_a", "subject_event_a");
        hashMap.put("subject_b", "subject_event_b");
        for (String s : hashMap.keySet()) {
            List<StudyBaseSubject> subjectsByTableName = eventMapper.selectSubjectsByEventId(eventId,s,hashMap.get(s));
            subjects.addAll(subjectsByTableName);
        }
        return subjects;
    }
}
